﻿//--------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2011 , JiaMingSoft TECH, Ltd. 
//--------------------------------------------------------------------

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNet.Utilities;

/// <remarks>
/// MainForm
/// 主页框架
///
///     2011.08.23 版本：1.0  LiangMingMing      创建代码。
///
/// 版本：1.0
///
/// <author>
///		<name>LiangMingMing</name>
///		<date>2011.08.23</date>
/// </author>
/// </remarks>
public partial class MainForm : System.Web.UI.Page
{
    // **********************************************************************************************
    // *                                                                                            * 
    // *                             Public Variate    公共变量                                     *
    // *                                                                                            * 
    // **********************************************************************************************

    /// <summary>
    /// 模块编号
    /// </summary>
    private string moduleCode = ConfigurationManager.AppSettings["RootMenuCode"];
    /// <summary>
    /// 默认子页面
    /// </summary>
    private string defaultPage = ConfigurationManager.AppSettings["DefaultPage"];
    /// <summary>
    /// 上框架页面
    /// </summary>
    private string topPage = ConfigurationManager.AppSettings["TopPage"];
    /// <summary>
    /// 下框架页面
    /// </summary>
    private string bottomPage = ConfigurationManager.AppSettings["BottomPage"];

    // **********************************************************************************************
    // *                                                                                            * 
    // *                             InitializeComponent  初始化                                    * 
    // *                                                                                            * 
    // **********************************************************************************************
      
    #region private void PageOnLoad() 页面初次加载时的动作
    /// <summary>
    /// 页面初次加载时的动作
    /// </summary>
    private void PageOnLoad()
    {
        // 读取参数
        this.GetParamter();
        if (Page.Request["Page"] != null)
        {
            this.defaultPage = Page.Request["Page"];
        }
        if (Page.Request["ContactID"] != null)
        {
            this.defaultPage += "&ContactID=" + Page.Request["ContactID"];
        }
        if (Page.Request["ReturnURL"] != null)
        {
            this.defaultPage += "&ReturnURL=" + Page.Request["ReturnURL"];
        }
        if (Page.Request["Category"] != null)
        {
            this.defaultPage += "?Category=" + Page.Request["Category"];
        }

        // 这里是设置默认加载的菜单 
        string leftPage = "LeftMenu.aspx?ModuleCode=" + moduleCode;
        if (Page.Request["Left"] != null)
        {
            leftPage = Page.Request["Left"];
        }
        string requestQuery = Page.Request.Url.Query;
        this.SetDefaultPage(this.parentfram, leftPage, this.defaultPage, requestQuery);
    }
    #endregion   

    // **********************************************************************************************
    // *                                                                                            * 
    // *                                       Method   操作方法                                    * 
    // *                                                                                            * 
    // **********************************************************************************************

    #region private void GetParamter() 读取参数
    /// <summary>
    /// 读取参数
    /// </summary>
    private void GetParamter()
    {
        // 客户公司名称
        string customerCompanyName = ConfigurationManager.AppSettings["SoftFullName"];
        // 软件名称
        string softFullName = ConfigurationManager.AppSettings["CustomerCompanyName"];
        // 设置标题
        this.Header.Title = customerCompanyName + " - " + softFullName;
    }
    #endregion

    #region public void SetDefaultPage(System.Web.UI.HtmlControls.HtmlGenericControl parentFrame, string leftPage, string mainPage, string requestQuery) 获取default.aspx页面的显示代码
    /// <summary>
    /// 获取default.aspx页面的显示代码
    /// </summary>
    /// <param name="parentframe">frameset,框架名称</param>
    /// <param name="myLeftUrl">默认指向的左框架页面地址</param>
    /// <param name="myMainUrl">默认指向的main框架页面地址</param>
    /// <param name="myQuery">左框架附带的信息</param>
    public void SetDefaultPage(System.Web.UI.HtmlControls.HtmlGenericControl parentFrame, string leftPage, string mainPage, string requestQuery)
    {
        //定义上框架、左框架打开与关闭的大小
        string frameHtml = "";

        //根据上框架开关决定显示的高度
        if ((new FrameInfo()).ShowTopFrame)
        {
            //如果上框架是展开的
            parentFrame.Attributes.Add("rows", (new FrameInfo()).TopExpandHeight + ",*," + (new FrameInfo()).BottomHeight);
        }
        else
        {
            //如果上框架是收缩的
            parentFrame.Attributes.Add("rows", (new FrameInfo()).TopShrinkHeight + ",*," + (new FrameInfo()).BottomHeight);
        }
        frameHtml = "<frame id=topfram src=\"" + topPage + requestQuery + "\" name=\"topFrame\" scrolling=\"NO\" noresize >";

        //根据左框架开关决定是否显示左框架
        if ((new FrameInfo()).ShowLeftFrame)
        {
            //如果左框架是展开的
            frameHtml += "<frameset id = myframeset cols=\"" + (new FrameInfo()).LeftWidth + ",*\" framespacing=\"0\" frameborder=\"no\" border=\"0\" >";
        }
        else
        {
            //如果左框架是收缩的
            frameHtml += "<frameset id = myframeset cols=\"0,*\" framespacing=\"0\" frameborder=\"no\" border=\"0\" >";
        }

        frameHtml += "<frame id=leftfram src=\"" + leftPage + requestQuery + "\" name=\"leftFrame\" scrolling=\"NO\" marginwidth=0>";
        frameHtml += "<frame id=fraContent src=\"" + mainPage + "\" name=\"fraContent\" scrolling=\"NO\">";
        frameHtml += "</frameset>";
        frameHtml += "<frame id=bottomfram src=\"" + bottomPage + requestQuery + "\" name=\"bottomFrame\" scrolling=\"NO\" noresize >";
        parentFrame.InnerHtml = frameHtml;
    }
    #endregion

    // **********************************************************************************************
    // *                                                                                            * 
    // *                                       EventArgs    事件方法                                * 
    // *                                                                                            * 
    // ********************************************************************************************** 

    #region protected void Page_Load(object sender, EventArgs e) 加载页面
    /// <summary>
    /// 加载页面
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // 检查用户是否登录
           // Utilities.CheckIsLogOn();
            this.PageOnLoad();
        }
    }
    #endregion
}

#region public class FrameInfo 获取当前模块的展开情况
/// <summary>
/// 获取当前模块的展开情况
/// </summary>
public class FrameInfo
{
    /// <summary>
    /// 左侧框架是否展开,默认为是
    /// </summary>
    private bool _LeftFrameIsOpen = true;
    /// <summary>
    /// 左侧框架是否展开,默认为是
    /// </summary>
    public bool ShowLeftFrame
    {
        get { return (this._LeftFrameIsOpen); }
        set { this._LeftFrameIsOpen = value; }
    }

    /// <summary>
    /// 顶部框架是否展开,默认为是
    /// </summary>
    private bool _TopFrameIsOpen = true;
    /// <summary>
    /// 顶部框架是否展开,默认为是
    /// </summary>
    public bool ShowTopFrame
    {
        get { return (this._TopFrameIsOpen); }
        set { this._TopFrameIsOpen = value; }
    }

    /// <summary>
    /// 左框架展开宽度
    /// </summary>
    private int _LeftWidth = 160;
    /// <summary>
    /// 顶部框架是否展开,默认为160
    /// </summary>
    public int LeftWidth
    {
        get { return (this._LeftWidth); }
        set { this._LeftWidth = value; }
    }

    /// <summary>
    /// 上框架展开高度
    /// </summary>
    private int _TopExpandHeight = 100;
    /// <summary>
    /// 上框架展开高度,默认100
    /// </summary>
    public int TopExpandHeight
    {
        get { return (this._TopExpandHeight); }
        set { this._TopExpandHeight = value; }
    }

    /// <summary>
    /// 上框架收缩高度
    /// </summary>
    private int _TopShrinkHeight = 50;
    /// <summary>
    /// 上框架收缩高度,默认50
    /// </summary>
    public int TopShrinkHeight
    {
        get { return (this._TopShrinkHeight); }
        set { this._TopShrinkHeight = value; }
    }

    /// <summary>
    /// 下框架高度
    /// </summary>
    private int _BottomHeight = 25;
    /// <summary>
    /// 下框架高度,默认25
    /// </summary>
    public int BottomHeight
    {
        get { return (this._BottomHeight); }
        set { this._BottomHeight = value; }
    }

    /// <summary>
    /// 构造器
    /// </summary>
    public FrameInfo()
    {
        Page p = new Page();
        try
        {
            p = (Page)System.Web.HttpContext.Current.Handler;

            this._LeftFrameIsOpen = p.Session["ShowLeftFrame"].ToString().ToLower().Equals("true");
            this._TopFrameIsOpen = p.Session["ShowTopFrame"].ToString().ToLower().Equals("true");

            this._LeftWidth = int.Parse(System.Configuration.ConfigurationManager.AppSettings["sysLeftWidth"].ToString());
            this._TopExpandHeight = int.Parse(System.Configuration.ConfigurationManager.AppSettings["sysTopOpenHeight"].ToString());
            this._TopShrinkHeight = int.Parse(System.Configuration.ConfigurationManager.AppSettings["sysTopOffHeight"].ToString());
            this._BottomHeight = int.Parse(System.Configuration.ConfigurationManager.AppSettings["sysBottomHeight"].ToString());
        }
        catch
        {
            //未取到,重新生成session
            p.Session["ShowLeftFrame"] = "True";
            p.Session["ShowTopFrame"] = "True";
        }
    }
}
#endregion
